package com.wx.ssm.aop;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * @author shkstart
 * @create 2020-05-08 15:08
 */


public class LogAround implements MethodInterceptor {
    @Override
    public Object invoke(MethodInvocation methodInvocation) throws Throwable {
        Object result = null;
        try{
            System.out.println("【接口-环绕】前置通知。。。");
            //methodInvocation.proceed()方法前的代码为：前置通知
            result = methodInvocation.proceed();//控制着目标方法执行，不写的话目标方法不执行
            //methodInvocation.proceed()方法后的代码为：后置通知
            System.out.println("【接口-环绕】后置通知：");
            System.out.println("目标对象"+methodInvocation.getThis()+"\n调用的方法名："+methodInvocation.getMethod().getName()+"\n方法的参数个数："+methodInvocation.getArguments().length+"\n方法的返回值为："+result);

        }catch (Exception e){
            //异常通知
            System.out.println("【接口-环绕】异常通知。。。。");
        }
        return result;//目标方法的返回值
    }
}

